{% extends 'base.html' %}
{% block self_head_css_js %}
    <script src="/static/layer/layer.js"></script>
{% endblock %}
{% block content %}
<script>
    window.onload=init;
    function init() {
        showhide(1);
    }
    function showhide(n) {
        var box = document.getElementById("navi");
        box.className="active";
        var box = document.getElementById("navi_manage");
        box.className="active";
    }
</script>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
    </section>

    <!-- Main content -->
    <section class="content">
        <form action="{% url 'delete' %}" method="post">
                {% csrf_token %}
            <div class="box">
                <div class="box-header">
                  <div class="btn-group">
						 <a href="{% url 'add' %}"><li class="btn btn-success" style="width: 60pt;font-size: medium" ><b>添加</b></li></a>
                  </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-striped table-bordered" id="dataform">
                      <thead>
                        <tr>
                            <th>
                                <input type="checkbox" onclick="checkAll(this, 'item1');" />
                            </th>
                                    <th>名称</th>
                                    <th>注释</th>
                                    <th>URL</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% if allnavi %}
                                {% for navi in allnavi %}
                                    <tr class="even gradeA">
                                        <td><input type="checkbox" id="u_id" class="item1" value="{{ navi.id }}" name="navi_check" /></td>
                                        <input type="hidden" name="u_name" value="{{ navi.name }}">
                                        <td><a href="#"><li style="list-style-type:none" onclick="return tanchu(this.value)" value="{{ navi.id }}">{{ navi.name }}</li></a></td>
                                        <td>{{ navi.description }}</td>
                                        <td>{{ navi.url }}</td>
                                    </tr>
                                {% endfor %}
                                {% else %}
                                    <p>No Item are available.</p>
                                {% endif %}

                            </tbody>
                  </table>
                <div class="btn-group">
						 <button class="btn btn-danger" style="width: 60pt;font-size: medium" onclick="return checkSubmit()"><b>删除</b></button>
                  </div>
                </div>
            </div>
        </form>

    </section>
        <!-- /.content -->
      </div>
<input id="handle_status" value="" hidden="hidden">
<script>
function checkAll(sender, checkClass) {
    var checkItems = document.getElementsByTagName('input');
    for (var i = 0; i < checkItems.length; i++) {
        var checkItem = checkItems[i];
        if (checkItem.type === 'checkbox' && checkItem.className === 'item1') {
            checkItem.checked = sender.checked;
        }
    }
}
</script>
<script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script>
  $(function () {
{#    $("#example1").DataTable();#}
    $('#dataform').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": true
    });
  });
</script>
<script>
function checkSubmit() {
    if (!confirm("确定删除？")) {
        window.event.returnValue = false;
    }
}
</script>
<script>
function tanchu(n){
    layer.open({
    type: 2,
    title: '修改信息',
    closeBtn: 1,
    area: ['600px', '400px'],
    shadeClose: true, //点击遮罩关闭
    content: ['/navi/edit?id=' + n,],
    end:function(){
            var handle_status = $("#handle_status").val();
            if ( handle_status == '1' ) {
                layer.msg('保存成功！',{
                    icon: 1,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                },function(){
                    history.go(0);
                });
            } else if ( handle_status == '2' ) {
                layer.msg('修改失败！',{
                    icon: 2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                },function(){
                    history.go(0);
                });
            }
        }
  });
}
</script>
{% endblock %}
